<?php


namespace app\admin\controller\product;

use app\admin\model\product\OrderModel;
use core\basic\Controller;

class OrderController extends Controller
{
    private $model;

    public function __construct()
    {
        $this->model = new OrderModel();
    }

    public function index()
    {
        if ((!!$id = get('id', 'int')) && $result = $this->model->getOrder($id)) {
            $this->assign('more', true);
            $this->assign('fields', $this->model->getOrder());
            $this->assign('member', $result);
        } else {
            $this->assign('list', true);
            if (!!($field = get('field', 'var')) && !!($keyword = get('keyword', 'vars'))) {
                $result = $this->model->findOrder($field, $keyword);
            } else {
                $result = object_array($this->model->getList());

            }
            // 会员等级

            $this->assign('product', array_to_object($result));
        }
        $this->display('product/order.html');
    }

    public function del()
    {
        if (!$id = get('id', 'int')) {
            error('传递的参数值错误！', -1);
        }
        if ($this->model->delOrder($id)) {
            $this->log('删除订单' . $id . '成功！');
            success('删除成功！', -1);
        } else {
            $this->log('删除订单' . $id . '失败！');
            error('删除失败！', -1);
        }
    }
}